package com.foo.CR;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by IntelliJ IDEA.
 * User: Tejas
 * Date: 12/30/10
 * Time: 1:22 PM
 *
 * The User is displayed with the 3 ringer profiles (Silent, Vibrate and Loud)
 * When the user select any of these, an entry in the map is created if not already present.
 * If already present, the entry is updated with the new profile information.
 */
public class SelectProfile extends ListActivity {

    String items[] = {"SILENT", "VIBRATE", "LOUD"};
    String _wifiID = "";

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.select_main);

        Intent getWiFiID = getIntent();
        _wifiID = getWiFiID.getStringExtra("SSID");

        _wifiID = Utils.cleanWifiID(_wifiID);

        TextView selection = (TextView) findViewById(R.id.selection);

        selection.setText("Select ringer profile for [" + _wifiID + "]");

        setListAdapter(new ArrayAdapter<String>(this,
                R.layout.wifi_row, R.id.wifiProfName, items));

    }

    public void onListItemClick(ListView parent, View v,
                                int position, long id) {

        MyWiFiMap myWiFiMap = MyWiFiMap.getMyWifiMap(this);
        if(items[position].equals("LOUD"))
        {
            myWiFiMap.addOrUpdate(_wifiID, Constants.RINGER_ACTION_LOUD);
            String msg = "Profile set to LOUD for " + _wifiID;
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        }
        if(items[position].equals("SILENT"))
        {
            myWiFiMap.addOrUpdate(_wifiID, Constants.RINGER_ACTION_SILENT);
            String msg = "Profile set to SILENT for " + _wifiID;
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        }
        if(items[position].equals("VIBRATE"))
        {
            myWiFiMap.addOrUpdate(_wifiID, Constants.RINGER_ACTION_VIBRATE);
            String msg = "Profile set to VIBRATE for " + _wifiID;
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        }

        finish();
    }

}
